﻿using AuthCenter.API.Application.Command.Account;
using AuthCenter.Domain.Account;
using AuthCenter.ErrorCode;
using AuthCenter.Intertructrue.Interface;
using MediatR;

namespace AuthCenter.API.Application.Handler.Account
{
    public class GetProvincesHandler : IRequestHandler<GetProvincesCommand, APIResult<List<ProvincesModel>>>
    {
        private readonly IBaseRepository<ProvincesModel> provincesRepo;

        public GetProvincesHandler(IBaseRepository<ProvincesModel> provincesRepo)
        {
            this.provincesRepo = provincesRepo;
        }
        public Task<APIResult<List<ProvincesModel>>> Handle(GetProvincesCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProvincesModel>> result = new APIResult<List<ProvincesModel>>();
            var res = provincesRepo.GetAll().Where(x => x.IsDel == false).ToList();
            result.Message = "显示成功";
            result.Code = APIEnum.Ok;
            result.Data = res;
            return Task.FromResult(result);
        }
    }
}
